package com.yf1706.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yf1706.bean.CountAbsenceDeduct;
import com.yf1706.bean.CountIncomeTaxRate;
import com.yf1706.bean.CountOvertimeSalaryRate;
import com.yf1706.bean.Emp;
import com.yf1706.bean.Salary;
import com.yf1706.bean.SalaryDetail;
import com.yf1706.service.CountSalaryService;
import com.yf1706.service.SalaryDetailService;
import com.yf1706.service.SalaryService;
import com.yf1706.vo.CheckMonthReportVO;
import com.yf1706.vo.CountBaseSalaryVO;
import com.yf1706.vo.CountFloatSalaryVO;
import com.yf1706.vo.CountSocialSecurityVO;

@Controller
@RequestMapping("countSalary")
public class CountSalaryController extends BaseController {

	@Autowired
	private CountSalaryService cSalaryService;
	
	@Autowired
	private SalaryDetailService salaryDetailService;

	@Autowired
	private SalaryService salaryService;
	
	/**
	 * 计算工资
	 */
	@RequestMapping("countSalary")
	@ResponseBody
	public void countSalary(HttpServletRequest request, HttpServletResponse response) {
		// 获得计算工资的年月
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date countDate = sdf.parse(request.getParameter("countDate"));
			int salaryId = Integer.parseInt(request.getParameter("salaryId"));
			int baseSalarySobId = Integer.parseInt(request.getParameter("baseSalarySobId"));
			int socialSecuritySobId = Integer.parseInt(request.getParameter("socialSecuritySobId"));
			int floatSalarySobId = Integer.parseInt(request.getParameter("floatSalarySobId"));
			List<CountBaseSalaryVO> BaseSalarys = cSalaryService.findBSBySidAndDate(baseSalarySobId, countDate);
			List<CountSocialSecurityVO> SocialSecuritys = cSalaryService.findSSBySidAndDate(socialSecuritySobId,countDate);
			List<CheckMonthReportVO> CheckReports = cSalaryService.findCRByDate(countDate);
			// 获得缺勤计算规则
			List<CountAbsenceDeduct> AbsenceDeducts = cSalaryService.queryAbsenceDeductAll();
			// 获得加班计算规则
			List<CountOvertimeSalaryRate> OvertimeRates = cSalaryService.queryOvertimeRateAll();
			// 根据时间和账套ID得到浮动工资值
			List<CountFloatSalaryVO> FloatSalarys = cSalaryService.findFSBySidAndDate(floatSalarySobId, countDate);
			// 获得个税税率表
			List<CountIncomeTaxRate> IncomeTaxRate = cSalaryService.queryTaxAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 将数据存进薪资详情表
	 */
	public void insertSD(int empId,String salaryItem,double salaryItemValue,int salaryId) {
		SalaryDetail salaryDetail = new SalaryDetail();
		Emp emp = cSalaryService.findEmpByID(empId);
		salaryDetail.setEmp(emp);
		salaryDetail.setSalaryItem(salaryItem);
		salaryDetail.setSalaryItemValue(salaryItemValue);
		Salary salary = salaryService.findBySalaryId(salaryId);
		salaryDetail.setSalary(salary);
		salaryDetailService.saveSD(salaryDetail);
	}

}
